package phan.connection;

import java.io.*;
import javax.jms.Session;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import phan.connection.ElementBean;
/**
 * Servlet implementation class for Servlet: LoginServlet
 *
 */
public class ValidePaiementProcess extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#HttpServlet()
     */

    public ValidePaiementProcess() {
        super();
    }

    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.print("day nhe");

        String _login = request.getParameter("login").toString();
        String _StockageName=request.getParameter("stockagenom").toString();
        String _email = request.getParameter("email").toString();
        System.out.print(_email);
        String _serie = request.getParameter("serie").toString();
        System.out.print("day    la"+_email);
        String _adminmail="hieuphan2003@yahoo.com";
        String subject ="activer votre ";
        String host= "192.168.0.14";
        boolean isValided = true;

        MySQLDBConnector connect = new MySQLDBConnector();
        connect.setNewStockID(_login,_StockageName,"10");
       // isValided = connect.MailPaiement(host,_adminmail, "dungbt84@gmail.com",_login,_StockageName,_serie);

        connect.close();
System.out.print("kiem tra valide"+isValided);
        if (isValided) {
            if(_serie.equals("banque"))
            { request.setAttribute("user", _login);
            RequestDispatcher disp;
            disp = request.getRequestDispatcher("/PHAN/ValidePaiementBanqueSuccess.jsp");
            disp.forward(request, response);
            }
             if(_serie.equals("cheque"))
            { request.setAttribute("user", _login);
            RequestDispatcher disp;
            disp = request.getRequestDispatcher("/PHAN/ValidePaiementChequeSuccess.jsp");
            disp.forward(request, response);
            }
             if(_serie.equals("cash"))
            { request.setAttribute("user", _login);
            RequestDispatcher disp;
            disp = request.getRequestDispatcher("/PHAN/ValidePaiementCashSuccess.jsp");
            disp.forward(request, response);
            }

        } else {
            request.setAttribute("isValide", "no");
            RequestDispatcher disp;
            disp = request.getRequestDispatcher("/PHAN/retry.jsp");
            disp.forward(request, response);
        }
    }
}